<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
    <link href="/static/css/index2.css" rel="stylesheet">
    <script type="text/javascript" src="/static/js/jquery-3.2.1.js"></script>
    <%--报表--%>
    <script src="/static/js/echarts.js"></script>

</head>
<body>
<%--为ECharts 准备一个定义了宽高的div--%>
<div id="main" style="width: 600px;height: 400px;"></div>
<script>
    // 基于准备好的dom，初始化echarts实例
    let myChart = echarts.init(document.getElementById('main'));
    let tname = [];//x轴 -- 条目
    let num = [];//y轴 -- 数量
    // 指定图表的配置项和数据
    let option = {
        title: {
            text: 'ECharts 入门示例'
        },
        tooltip: {},
        legend: {
            data: ['销量']
        },
        xAxis: {
            data: tname
        },
        yAxis: {},
        series: [
            {
                name: '销量',
                type: 'bar',
                data: num
            }
        ]
    };
    $.get(
        "/mains/getReport",
        function (list) {
            for(let i in list){
                tname.push(list[i].yname);
                num.push(list[i].num);
            }
            // 使用刚指定的配置项和数据显示图表。
            myChart.setOption(option);
        }
    )

</script>
</body>
</html>